<template>
	<!--pages/agent/myAgent/agentData.wxml-->
	<view class="page">
		<view class="head">
			<view url="" class="photo" hover-class="none">
				<image :src="user.imgUrl?user.imgUrl:'/static/img/index/photo.png'" style="width:61px;height:61px;">
				</image>
			</view>
			<view class="user">
				<view>
					<text class="name">{{user.userName}}</text>
				</view>
				<view>{{user.phone}}</view>
			</view>
		</view>
		<view class="agent_data">
			<view class="agent_center">
				<view class="agent_list">
					<view>
						<view class="agent_num">{{user.userNum}}</view>
						<view class="agent_active">服务商数</view>
					</view>
					<view>
						<view class="agent_num">{{formatDate(user.createDate)}}</view>
						<view class="agent_active">注册时间</view>
					</view>
					<view>
						<view class="agent_num">{{user.inviteCode}}</view>
						<view class="agent_active">展业码</view>
					</view>
				</view>
			</view>
		</view>
		<view class="box">
				<!-- 当设置tab-width,指定每个tab宽度时,则不使用flex布局,改用水平滑动 -->
				<!-- <me-tabs class="TD-metab" v-model="tabIndex" :tabs="tabs"></me-tabs> -->

				<Goodme-tabs class="TD-metab" v-model="tabIndex" :tabs="tabs"  @change="swiperChange"></Goodme-tabs>
				<view class="" :style="{height: height}">
					<mescroll-uni @init="mescrollInit" :height="height" :down="downOption" @down="downCallback" :up="upOption"
						@up="upCallback">
						<!-- 	<view class="deliver-query" v-if="keyword=='1'">
								<view class="deliver-time" ontap="showPopup">
					
									<image src="/static/img/index/query_time.png" style="width:28rpx;height:28rpx;"></image>
									<picker mode="date" :value="startDeta" :start="startTime" :end="endTime" @change="startDateChange">
										<view class="picker">
											{{startDeta}}
										</view>
									</picker>
					
								</view>
								<view class="line">至</view>
								<view class="deliver-time" ontap="showPopup">
					
									<image src="/static/img/index/query_time.png" style="width:28rpx;height:28rpx;"></image>
									<picker mode="date" :value="endTime" :start="startDeta" :end="endTime" @change="endDateChange">
										<view class="picker">
											{{endDetaL}}
										</view>
									</picker>
								</view>
								<button class="queryBut" @click="search">查询</button>
							</view> -->
							<!--  @click="todetails(item)" -->
							<view class="list-item" v-for="(item,index) in records">
								<view class="list-deta">{{item.days}}</view>
								<view class="list-center">
									<view class="center-left">
										<view class="center-title">交易金额</view>
										<view class="center-title">{{item.trxAmt}}元</view>
									</view>
									<view class="center-left">
										<view class="center-title">收益</view>
										<view class="center-title">{{item.syAmt}}元</view>
									</view>
								</view>
								<view class="list-bottom">
									<view class="bottom-left">
										<view class="bottom-item">
											<view class="bottom-title">服务商总数</view>
											<view class="bottom-number">{{item.addUser}}</view>
										</view>
										<view class="bottom-item">
											<view class="bottom-title">商户总数</view>
											<view class="bottom-number">{{item.jihuoNum}}</view>
										</view>
										<view class="bottom-item">
											<view class="bottom-title">达标奖励</view>
											<view class="bottom-number">{{item.dabiaoAmt}}</view>
										</view>
										<view class="bottom-item">
											<view class="bottom-title">分红奖励</view>
											<view class="bottom-number">{{item.bonusAmt||0}}</view>
										</view>
										<view class="border"></view>
									</view>
									<view class="bottom-left">
										<view class="bottom-item">
											<view class="bottom-title">分润奖励</view>
											<view class="bottom-number">{{item.fenrunAmt}}</view>
										</view>
										<view class="bottom-item">
											<view class="bottom-title">激活奖励</view>
											<view class="bottom-number">{{item.activationAmt}}</view>
										</view>
										<view class="bottom-item">
											<view class="bottom-title">礼包奖励</view>
											<view class="bottom-number">{{item.lbAmt||0}}</view>
										</view>
										<view class="bottom-item">
											<view class="bottom-title">运营中心补贴</view>
											<view class="bottom-number">{{item.yyzxBtAmt||0}}</view>
										</view>
									</view>
								</view>
							</view>
					
						<!-- </view> -->
					</mescroll-uni>
				</view>

		</view>
	</view>
</template>

<script>
	import number from "../../utils/number.js";
	import MescrollItem from "./mescroll-swiper-item.vue";
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import MescrollMoreItemMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mixins/mescroll-more-item.js";
	const api = require('../../config/api');
	const util = require('../../utils/util');
	export default {
		components: {
			MescrollItem
		},
		mixins: [MescrollMixin, MescrollMoreItemMixin], // 注意此处还需使用MescrollMoreItemMixin (必须写在MescrollMixin后面)
		data() {
			return {
				number: number, //声明number属性并赋值为引入的number模块
				user: {},
				height: "", // 需要固定swiper的高度
				tabs: [{

						dictLabel: "日业绩",


						dictValue: "1",

					},
					{

						dictLabel: "月业绩",


						dictValue: "2",

					},
					{

						dictLabel: "全部业绩",


						dictValue: "3",

					}
				],
				// tabs: [{name:'直属',type:0}],
				tabIndex: 0 ,// 当前tab的下标
				downOption: {
					auto: true // false不自动加载 (mixin已处理第一个tab触发downCallback)
				},
				upOption: {
					auto: false, // 不自动加载
					textLoading: '加载中 ...', // 加载中的提示文本
					textNoMore: '暂无更多', // 没有更多数据的提示文本
					// page: {
					// 	num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
					// 	size: 10 // 每页数据的数量
					// },
					noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty: {
						// use: false,
						icon: "",
						tip: '~ 暂无数据 ~', // 提示
						btnText: ''
					}
				},
				records: [], //列表数据
				startDeta: '开始时间',
				endDetaL: '结束时间',
				keyword: ''


			}
		},
		onLoad() {
			// this.getUserInfo();
			this.user = uni.getStorageSync('agentInfo')
				this.height = uni.getSystemInfoSync().windowHeight - uni.upx2px(64) + 'px'
		},
		methods: {
			async getUserInfo() {
				const res = await util.request(
					api.getUserInfoUrl, {
						
					},
					'POST'
				);
				console.log(res);
				if (res.code !== 0) {
					uni.showToast({
						title: res.msg,
						icon: "none"
					})
			
				} else {
					this.user = res.data.user || {}
					
				}
			},
			// 轮播菜单
			swiperChange(e) {
				// this.tabIndex = e.detail.current
				// console.log(this.tabIndex );
				this.records = []
					this.mescroll.resetUpScroll() // 再刷新列表数据
					// this.mescroll.resetUpScroll()
			},
			  formatDate(time) { //设置时间转换格式
			  let date = new Date(time);
			    var y = date.getFullYear(); //获取年
			    var m = date.getMonth() + 1; //获取月
			    m = m < 10 ? '0' + m : m; //判断月是否大于10
			    var d = date.getDate(); //获取日
			    d = d < 10 ? ('0' + d) : d; //判断日期是否大10
			    return y + '-' + m + '-' + d; //返回时间格式
			  },
			search(){
				this.downCallback();
			},
			startDateChange: function(e) {
				this.startDeta = e.detail.value
			},
			endDateChange: function(e) {
				this.endDetaL = e.detail.value
			},
			menuClick(index) {
				this.auditStatus = index
				this.downCallback();
			
			
			},
			
			// 代理商详情
			todetails(item) {
				uni.navigateTo({
					url: '/pages/indexChild/GoodsDetails/GoodsDetails?goodsId=' + item.id
				});
			},
			/*下拉刷新的回调 */
			downCallback() {
				// 这里加载你想下拉刷新的数据, 比如刷新轮播数据
				// loadSwiper();
				// 下拉刷新的回调,默认重置上拉加载列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
				this.mescroll.resetUpScroll()
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
			
				//联网加载数据
				// this.mescroll.endErr();
				// this.keyword = this.tabs[this.i].dictValue
				this.keyword = this.tabs[this.tabIndex].dictValue
				if(this.keyword != 1){
					this.startDeta = '开始时间'
					this.endDetaL =  '结束时间'
				}
				let user = uni.getStorageSync('agentInfo')
				// let keyword = this.tabs[this.i].dictValue
				let keyword =this.tabs[this.tabIndex].dictValue
				let pageNum = page.num; // 页码, 默认从1开始
				let pageSize = page.size; // 页长, 默认每页10条
				const res = util.request(
					api.skUrl, {
						endTime: this.endDetaL=='结束时间'?'':this.endDetaL,
						limit: 10,
						page: 1,
						startTime: this.startDeta=='开始时间'?'':this.startDeta,
						type: keyword,
						userId: user.id,
			
					},
					'POST'
				).then(res => {
					// console.log(res);
					//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
					let totalPage = res.data.pages;
					this.mescroll.endByPage(res.data.records.length, totalPage); //必传参数(当前页的数据个数, 总页数)
					// this.mescroll.endSuccess(res.data.records.length);
					//设置列表数据
					if (page.num == 1) this.records = []; //如果是第一页需手动制空列表
					this.records = this.records.concat(res.data.records); //追加新数据
				}).catch(() => {
					//联网失败, 结束加载
					this.mescroll.endErr();
				})
			},
			//点击空布局按钮的回调
			emptyClick() {
				uni.showToast({
					title: '点击了按钮,具体逻辑自行实现'
				})
			}
			
		}
	}
</script>
<style>
	page {
		height: 100%;
		background-color: white;
	}
	.mescroll-upwarp {
		min-height: 0rpx !important;
	}
</style>
<style lang="scss" scoped>
	.page {
		display: flex;
		flex-direction: column;
		height: 100%;
		overflow: hidden;
	}
	.head {
		display: flex;
		align-items: center;
		padding: 50rpx 0 150rpx 32rpx;
		background-color: #6A9FFB;

	}

	.photo {
		display: flex;
	}

	.photo image {
		display: block;
		border-radius: 50%;
		overflow: hidden;
	}

	.user {
		padding: 0 40rpx;
		color: white;
	}

	.name {
		font-size: 36rpx;
		font-weight: 600;
	}

	.agent_data {
		position: relative;
		height: 80px !important;
		width: 100%;
	}

	.agent_center {
		position: absolute;
		left: 32rpx;
		right: 32rpx;
		bottom: -5rpx;
		background-color: white;
		border-radius: 20rpx;
		box-shadow: 0px 1px 2px 3px rgba(0, 0, 0, 0.05);
	}

	.agent_list {
		display: flex;
		padding: 30rpx 0;
	}

	.agent_list>view {
		width: 33.33%;
		text-align: center;
		font-size: 28rpx;
	}

	.agent_list>view:nth-child(1),
	.agent_list>view:nth-child(2) {
		border-right: 1rpx solid #f5f5f5;
	}

	.agent_num {
		padding-bottom: 10rpx;
	}

	.agent_active {
		color: #AAAAAA;
	}

	.agent_show {
		color: #48D33D;
	}

	.agent_my {
		background-color: white;
	}
	.box {
		margin-top: 10px;
	
		flex: 1;
	}
	.goodsname {
		font-size: 28rpx;
		padding: 15rpx 30rpx 0 30rpx;
	}
	
	.goodsprice {
		padding: 0 30rpx 10rpx 30rpx;
	}
	
	.goodsprice>text:first-child {
		color: #E30F06;
		font-size: 22rpx;
	}
	
	.goodsprice>text:last-child {
		color: #E30F06;
		font-size: 28rpx;
	}
	
	.list-item {
		padding: 0 30rpx;
		border-bottom: 10rpx solid #eee;
	}
	
	.list-deta {
		font-size: 30rpx;
		padding: 25rpx 0;
	}
	
	.list-center {
		// background-color: #FF445B;
		background-color: #6A9FFB;
		display: flex;
		justify-content: space-around;
		align-items: center;
		padding: 20rpx 0;
		border-radius: 10rpx;
	}
	
	.center-left {
		text-align: center;
	}
	
	.center-title {
		font-size: 30rpx;
		color: #ffffff;
		padding: 5rpx 0;
	}
	
	.list-bottom {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding-top: 25rpx;
	}
	
	.bottom-left {
		width: 46%;
		position: relative;
	}
	
	.border {
		position: absolute;
		right: -30rpx;
		top: 10rpx;
		width: 5rpx;
		height: 160rpx;
		background-color: #eee;
	}
	
	.bottom-item {
		display: flex;
		justify-content: space-between;
		align-content: center;
		padding-bottom: 15rpx;
	}
	
	.box {
	flex: 1;
		margin-bottom: 30rpx;
	}
	
	.van-tabs__wrap {
		border-bottom: 5px solid #eee;
	}
	
	.deliver-query {
		padding-top: 20rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		overflow: hidden;
		width: 690rpx;
		margin: 0rpx auto;
	}
	
	.deliver-time {
		color: #AEAEAE;
		font-size: 26rpx;
		width: 35%;
		height: 62rpx;
		line-height: 62rpx;
		text-align: center;
		background: white;
		/* border: 1px solid #AEAEAE; */
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 10rpx;
		border: 1rpx solid #f5f5ff;
	}
	
	.deliver-time>text {
		padding-left: 10rpx;
	}
	
	.line {
		color: #D2D2D2;
		font-size: 30rpx;
		padding: 0 20rpx;
	}
	
	.picker {
		padding-left: 15rpx;
	}
	
	.queryBut {
		width: 100rpx;
		height: 62rpx;
		background-color: #6A9FFB;
		font-size: 25rpx;
		padding: 0rpx;
		color: #fff;
		line-height: 62rpx;
		margin-left: 25rpx;
	}
	
	.queryBut::after {
		border: 0;
	
	}
	
	.bottom {
		display: flex;
		justify-content: center;
		padding: 40rpx 0;
	}
	
	.van-divider {
		border: none !important;
	}
</style>